<?php
	class UserModel extends Model {
		function UserModel()
		{
			parent::Model();			
		}
		
		function addUser($user)
		{
			if($user['username'] != null) {
				$this->load->helper('security');
				$data = array(
	               'username' => $user['username'] ,
	               'password' => dohash($user['password']) ,
	               'profile' => $user['profile'],
				   'is_active' => 1
	            );
	            $this->db->set('create_by', "'". $this->session->userdata('username') ."'", FALSE);
	            $this->db->set('create_date', 'NOW()', FALSE); 
				$this->db->insert('users', $data);
			} 
		}
		
		function updateUser($user)
		{
			$this->load->helper('security');
			if($user['username'] != null) {
			$data = array(
               'password' => dohash($user['password']) ,
			   'update_by' => $this->session->userdata('username')
            );
            $this->db->set('update_date', 'NOW()', FALSE); 
			$this->db->where('username', $user['username']);
			$this->db->update('users', $data);
			} 
		}
		
		function deleteUser($user)
		{
            $this->db->where('username', $user); 
			$this->db->delete('users'); 
		}
		
		function getUserByUsername($user)
		{
			$query = $this->db->get_where('users', array('username' => $user, 'is_active' => 1));
			return $query->row_array();
		}
	}
?>